package kr.couponplay.android.extention;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;

public class GalleryFling extends Gallery {

	public GalleryFling(Context context) {
		super(context);
	}
	
	public GalleryFling(Context context, AttributeSet attrs) {
		super(context, attrs);
//		float ppi = context.getResources().getDisplayMetrics().density * 160.0f;
//		mDeceleration = SensorManager.GRAVITY_EARTH * 39.37f * ppi * ViewConfiguration.getScrollFriction();
	}
	
	@Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
//		mDistanceX += distanceX;
		return super.onScroll(e1, e2, distanceX, distanceY);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
//		if (event.getAction() == MotionEvent.ACTION_DOWN) {
//		    mDistanceX = 0;
//		}
		return super.onTouchEvent(event);
    }
    
	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		int keyCode;
		if (e2.getX() > e1.getX()) {
			keyCode = KeyEvent.KEYCODE_DPAD_LEFT;
		} else {
			keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;
		}
		onKeyDown(keyCode, null);
		return true;
	}

//	private float mDeceleration;
//	private float mDistanceX;	
//	@Override
//	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//		float toMoveDistance = getWidth() - Math.abs(mDistanceX);
//		float maxVelocity = (float) Math.sqrt(toMoveDistance * mDeceleration * 2);
//		float revisedVelocityX = 0;
//
//		if (velocityX > 0) {
//		    revisedVelocityX = Math.min(velocityX, maxVelocity);
//		} else {
//		    revisedVelocityX = Math.max(velocityX, -maxVelocity);
//		}
//
//		return super.onFling(e1, e2, revisedVelocityX, velocityY);
//	}
}
